<?php
namespace Action;
use HY\Action;
!defined('HY_PATH') && exit('HY_PATH not defined.');
class Log extends HYBBS {
	public function __construct(){
		parent::__construct();
		//{hook a_index_init}
		if(!IS_LOGIN){
			if(IS_AJAX && IS_POST){
				die($this->json(array('error'=>false,'info'=>'请登录后再操作')));
			}
			else{
				header("location: ". HYBBS_URLA('user','login'));
				die;
			}

		}
	}
	public function showLog(){
		$this->view = 'FHL';
		$this->display('logs');
	}
	public function getEventLog(){
	    $sEcho = X("post.sEcho");
	    $sSearch = trim(X("post.sSearch"));
	    $iDisplayStart = X("post.iDisplayStart");
	    $iDisplayLength = X("post.iDisplayLength");
	    $tmp =  S('fhl_ctask')->query("
					SELECT count(*) un,min(eid) min,max(eid) max FROM eventlog ")->fetchALL()[0];
        $data=[];
	    if($sSearch==""){
            $start = $tmp["max"]-$iDisplayStart-$iDisplayLength;
            $data = S('fhl_ctask')->query("
					select * from (SELECT * FROM eventlog where eid> $start  limit ".$iDisplayLength.") t order by eid desc ")->fetchALL();
        }else{
            $data = S('fhl_ctask')->query("
					SELECT * FROM eventlog where content like '%".$sSearch."%' order by eid desc")->fetchALL();
        }
		$this->json([
		        "sEcho"=>$sEcho,
				"iTotalRecords"=>$tmp["un"], //数据总行数
  				"iTotalDisplayRecords"=>$tmp["un"], //数据总行数
  				"aaData"=>$data
		]);
	}
    public function getServerLog(){
        $sEcho = X("post.sEcho");
        $sSearch = trim(X("post.sSearch"));
        $iDisplayStart = X("post.iDisplayStart");
        $iDisplayLength = X("post.iDisplayLength");
        $tmp =  S('fhl_ctask')->query("
					SELECT count(*) un,min(lid) min,max(lid) max FROM serverlog ")->fetchALL()[0];
        $data=[];
        if($sSearch==""){
            $start = $tmp["max"]-$iDisplayStart-$iDisplayLength;
            $data = S('fhl_ctask')->query("
					select * from  (SELECT * FROM serverlog where lid> ".$start."  limit ".$iDisplayLength.") t order by lid desc   ")->fetchALL();
        }else{
            $data = S('fhl_ctask')->query("
					SELECT * FROM serverlog where fname like '%".$sSearch."%' order by lid desc")->fetchALL();
        }
        $this->json([
            "sEcho"=>$sEcho,
            "iTotalRecords"=>$tmp["un"], //数据总行数
            "iTotalDisplayRecords"=>$tmp["un"], //数据总行数
            "aaData"=>$data
        ]);
    }
    public function getClientLog(){
        $sEcho = X("post.sEcho");
        $sSearch = trim(X("post.sSearch"));
        $iDisplayStart = X("post.iDisplayStart");
        $iDisplayLength = X("post.iDisplayLength");
        $tmp =  S('fhl_ctask')->query("
					SELECT count(*) un,min(lid) min,max(lid) max FROM clientlog ")->fetchALL()[0];
        $data=[];
        if($sSearch==""){
            $start = $tmp["max"]-$iDisplayStart-$iDisplayLength;
            $data = S('fhl_ctask')->query("
					select * from (SELECT * FROM clientlog where lid> ".$start."  limit ".$iDisplayLength." ) t order by lid desc")->fetchALL();
        }else{
            $data = S('fhl_ctask')->query("
					SELECT * FROM clientlog where fname like '%".$sSearch."%' order by lid desc")->fetchALL();
        }
        $this->json([
            "sEcho"=>$sEcho,
            "iTotalRecords"=>$tmp["un"], //数据总行数
            "iTotalDisplayRecords"=>$tmp["un"], //数据总行数
            "aaData"=>$data
        ]);
    }

	
	
	//{hook a_index_fun}
}
